Skip to content

Fix WorkshopsController#rsvp 500 when member already has a nil-attending invitation - #2791

Merged
mroderick merged 4 commits into
masterfrom
fix/workshop-rsvp-nil-invitation
Aug 7, 2026
Merged

Fix WorkshopsController#rsvp 500 when member already has a nil-attending invitation#2791
mroderick merged 4 commits into
masterfrom
fix/workshop-rsvp-nil-invitation

Conversation

@mroderick

Copy link
Copy Markdown
Collaborator

Closes #2790

Summary

Fixes a 500 error when a member clicks Attend as a coach/student on a workshop where they already have a WorkshopInvitation row for that workshop + role with attending NULL.

Root cause

find_or_create_invitation used WorkshopInvitation.create_or_find_by. In Rails 8.1, create_or_find_by calls the non-bang create. When the uniqueness validation fails (row already exists), it returns an unpersisted record with id: nil. The subsequent redirect_to invitation_path(@invitation) then raises ActionController::UrlGenerationError.

Fix

After create_or_find_by, check persisted?. If the record is not persisted, fall back to WorkshopInvitation.find_by(workshop:, member:, role:) to return the existing row.

Verification

  • Added spec/controllers/workshops_controller_spec.rb covering:
    • Existing nil-attending invitation for the workshop + role redirects to the existing invitation page.
    • No new invitation is created in that case.
    • Member without an invitation still creates one.
    • Already-attending member is redirected back with the existing message.
  • Ran the new spec and all controller/request specs:
    • bundle exec rspec spec/controllers/workshops_controller_spec.rb — 4 examples, 0 failures
    • bundle exec rspec spec/controllers/ spec/requests/ — 136 examples, 0 failures
  • bundle exec rubocop app/controllers/workshops_controller.rb spec/controllers/workshops_controller_spec.rb — no offenses

Post-Deploy Monitoring & Validation

  • Monitor error tracking for ActionController::UrlGenerationError with controller: "workshop_invitation", id: nil in WorkshopsController#rsvp.
  • Expected signal: zero occurrences after deploy.
  • If occurrences persist, verify the member/workshop/role combination and check for invitations that cannot be found by find_by (e.g. unique index vs validation mismatch).

@mroderick
mroderick requested a review from olleolleolle August 7, 2026 09:41
@mroderick
mroderick marked this pull request as ready for review August 7, 2026 09:41
Comment thread spec/controllers/workshops_controller_spec.rb Outdated
Comment thread app/controllers/workshops_controller.rb Outdated

@olleolleolle olleolleolle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably helps!

mroderick and others added 3 commits August 7, 2026 14:43
@mroderick
mroderick merged commit 96543ec into master Aug 7, 2026
10 checks passed
@mroderick
mroderick deleted the fix/workshop-rsvp-nil-invitation branch August 7, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WorkshopsController#rsvp crashes with 'No route matches ... id: nil' when member already has a workshop invitation

3 participants